<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>网站监控系统</title>
    <link rel="stylesheet" type="text/css" href="./static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="./static/admin/css/login.css"/>
    
    <script type="text/javascript" src="./static/js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="./static/js/my.js"></script>

</head>

<body>
<div class="m-login-bg">
    <div class="m-login">
        <h3>登录页</h3>
        <div class="m-login-warp">
            <form class="layui-form">
                <div class="layui-form-item">
                    <input type="text" id="email" name="email" required lay-verify="email" placeholder="邮箱"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input type="text" id="password" name="password" required lay-verify="required" placeholder="密码"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input type="text" name="verity" required lay-verify="required" placeholder="验证码,点击验证" autocomplete="off"
                           class="layui-input" id="TencentCaptcha" data-appid="2001614463" data-cbfn="callback">
                </div>
                <div class="layui-form-item m-login-btn">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
                    </div>
                    <div class="layui-inline">
                        <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                    </div>
                </div>
                <div class="layui-form-item">
                    还没注册？<a href="/register.html"><b>点击注册</b></a> &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp <a href="/forget_check.html"><b>忘记密码？</b></a>
                </div>
            </form>
        </div>
        <p class="copyright">Copyright 2019 </p>
    </div>
</div>
<script src="./static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="http://pv.sohu.com/cityjson"></script>
<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
<script>
    var dic = new Array();
    window.callback = function (res) {

        if (res.ret === 0) {
            $("#TencentCaptcha").val("验证通过");
            $("#TencentCaptcha").hide();
            dic = res;

        } else {
            alert("验证失败了");
        }
    };


    // alert(returnCitySN["cip"]+','+returnCitySN["cname"]);
    layui.use(['form', 'layedit', 'laydate'], function () {

        var form = layui.form(),
            layer = layui.layer;


        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            password: [/(.+){6,12}$/, '密码必须6到12位'],
            verity: [/(.+){6}$/, '验证码必须是6位'],

        });
        //监听提交
        form.on('submit(login)', function(d) {
            dic['UserIP'] = returnCitySN["cip"];
            var dataj = {"verify":dic, "email":$("#email").val(),"password" : $("#password").val()};
            $.ajax(
                {
                    url:'/api/user/login?key=ef6c288e29f8490c8b5ec8d4ec2a',
                    type:'POST',
                    data:JSON.stringify(dataj),
                    xhrFields: {
                        withCredentials: true
                    },
                    success:function(obj) {
                        if(obj.code == 20){
                            alert("登录成功");
                            // $(location).attr('href', 'index.html');
                            window.location.href='/index.html';
                        }
                        else {
                            if(obj.msg.search("verify") != -1){
                                alert("验证失败，请重试！")
                            }else{
                                alert(obj.msg);

                            }
                            // $('#error_msg').text(obj.msg)
                        }
                    },
                    error:function(obj) {
                        alert('未知错误');
                    }
                }
            );
            return false;
        });
    });
</script>

</body>

</html>